package com.jiuyi.controller;

import com.jiuyi.common.R;
import com.jiuyi.entity.AddressBook;
import com.jiuyi.service.Impl.AddressBookServiceImpl;
import com.jiuyi.vo.AddressBookSelectListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * DATA: 2022/10/23
 * Author: 晨夕
 */
@RestController
@RequestMapping("/addressBook")
public class AddressBookController {

    @Autowired
    private AddressBookServiceImpl addressBookServiceImpl;

    /**
     * 添加收货地址
     */
    @PostMapping
    public R addressBook(@RequestBody AddressBook addressBook, HttpServletRequest request){
        return addressBookServiceImpl.getAddressBook(addressBook,request);
    }
    /**
     * 查询收货地址列表
     */
    @GetMapping("/list")
    public R<AddressBookSelectListVo> selectAddressBookList(HttpServletRequest request){
        return addressBookServiceImpl.selectAddressBookList(request);
    }
    /**
     * 设置默认地址
     */
    @PutMapping("/default")
    public R updateDetail(@RequestBody AddressBookSelectListVo addressBookSelectListVo,HttpServletRequest request){
        return addressBookServiceImpl.updateDetail(addressBookSelectListVo.getId(),request);
    }
    /**
     * 跟据id查询地址
     */
    @GetMapping("/{id}")
    public R<AddressBookSelectListVo> selectById(@PathVariable("id")Long id){
        return addressBookServiceImpl.selectById(id);
    }
    /**
     * 修改收货地址
     */
    @PutMapping
    public R updateAddressBook(@RequestBody AddressBook addressBook){
        return addressBookServiceImpl.updateAddressBook(addressBook);
    }
    /**
     * 根据id删除地址
     */
    @DeleteMapping
    public R deleteAddressBook(Long ids){
        return addressBookServiceImpl.deleteAddressBook(ids);
    }
    /**
     * 获取默认地址
     */
    @GetMapping("/default")
    public R<AddressBook> selectDefaultAddressBook(HttpServletRequest request){
        return addressBookServiceImpl.selectDefaultAddressBook(request);
    }
}
